package com.edu.controller;

import com.edu.bean.User;
import com.edu.serivce.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String userLogin(User user, Model model, HttpSession session){
        Map<String, Object> map = userService.userLogin(user);

        if(map.get("loginUser")!=null){
            session.setAttribute("loginUser",map.get("loginUser"));
            return "redirect:/student.jsp";
        }

        model.addAttribute("msg",map.get("msg"));
        return "forward:/login.jsp";
    }

}
